import os
import sys

from core.rest_client import RestClient
from common.read_data import data

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)
data_file_path = os.path.join(BASE_PATH, "config", "setting.ini")
api_root_url = data.load_ini(data_file_path)["host"]["api_root_url"]


class Folder(RestClient):

    def __init__(self, api_root_url, **kwargs):
        super(Folder, self).__init__(api_root_url, **kwargs)

    def newtree(self, **kwargs):
        '''
        获取工作表所有的文件夹
        '''
        return self.post("/api/folder/newtree", **kwargs)

    def create(self,**kwargs):
        '''
        创建工作表文件夹
        '''
        return self.post("/api/folder/create", **kwargs)

    def change(self, **kwargs):
        '''
        移动工作表
        '''
        return self.post("/api/folder/change", **kwargs)


    def change_batch(self, **kwargs):
        '''
        批量移动工作表
        '''
        return self.post("/api/folder/change_batch", **kwargs)

    def modify(self, access_token, **kwargs):
        '''
        编辑文件夹
        '''
        return self.get("/api/project/modify?access_token={}".format(access_token), **kwargs)

    def delete(self, **kwargs):
        '''
        删除工作表文件夹
        '''
        return self.post("/api/folder/delete", **kwargs)


    def newfilter(self, **kwargs):
        '''
        搜索工作表或工作表文件夹
        '''
        return self.get("/api/folder/newfilter", **kwargs)


    def new_list_only_tb(self, **kwargs):
        '''
        搜索工作表文件夹下的工作表
        '''
        return self.get("/api/folder/new_list_only_tb", **kwargs)




folder = Folder(api_root_url)
